﻿using GM_Shop.BLL;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace GM_Shop.Controllers
{
    public class GMShopController : Controller
    {
        [HttpGet]
        public ActionResult LogIn() //登录页面
        {
            return View();
        }

        [HttpPost]
        public ActionResult LogIn(string name, string pwd) //登录
        {
            int id = 0;
            var json = new LogInMethod().logIn(name, pwd, ref id);
            if (id != 0) { 
                Session["UserId"] = id;
                Session["UserName"] = name;
            }
            return Json(json);
        }

        [HttpGet]
        public ActionResult Home() //主页
        {
            return View();
        }

        [HttpGet]
        public ActionResult ShoppingCart() //购物车
        {
            return View();
        }

        [HttpGet]
        public ActionResult Register() //注册
        {
            return View();
        }

        [HttpGet]
        public ActionResult ProductList(string Id) //商品列表
        {
            if (!int.TryParse(Id, out int i)) return RedirectToAction("Home");
            ViewBag.PageName = new CommodityInfo().getCommodityName(Convert.ToInt32(Id));
            return View();
        }

        [HttpGet]
        public ActionResult Help() //帮助
        {
            return View();
        }

        [HttpGet]
        public ActionResult CommodityInfo(string Cid) {
            if (!int.TryParse(Cid, out int i)) return RedirectToAction("Home");
            var info = new CommodityInfo().getCommodityInfo(Convert.ToInt32(Cid));
            if(info==null)
                return RedirectToAction("Home");
            return View(info);
        }
    }
}